package com.skyolder.milkbee.web.rest.my;

import java.net.URISyntaxException;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.codahale.metrics.annotation.Timed;
import com.skyolder.milkbee.domain.Gift;
import com.skyolder.milkbee.domain.Leaguer;
import com.skyolder.milkbee.dto.SimpleResult;
import com.skyolder.milkbee.service.GiftService;
import com.skyolder.milkbee.web.util.WebUserUtil;

/**
 * REST controller for managing Gift.
 */
@RestController("myGiftResource")
@RequestMapping("/api/my")
public class GiftResource {

    private final Logger log = LoggerFactory.getLogger(GiftResource.class);
        
    @Inject
    private GiftService giftService;

    @Inject
    private  WebUserUtil webUserUtil;


    /**
     * GET  /gifts : get all the gifts.
     *
     * @param pageable the pagination information
     * @return the ResponseEntity with status 200 (OK) and the list of gifts in body
     * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
     */
    //gift/send/'+giftId+'/'+userId
    @PostMapping("/gift/send/{giftId}/{userId}")
    @Timed
    public  ResponseEntity<SimpleResult> sendGift(@PathVariable Long giftId,@PathVariable Long userId)
        throws URISyntaxException {
        SimpleResult sr = new SimpleResult();
        Leaguer senderleaguer=webUserUtil.getCurrentLeaguer();
        Leaguer reciverleaguer =webUserUtil.getByUserId(userId);
        Gift  gift=giftService.findOne(giftId);
        boolean success=giftService.sendGift(gift,senderleaguer,reciverleaguer);
        sr.setSuccess(success);
        return new ResponseEntity<>(sr, HttpStatus.OK);
    }



}
